#include "device/ec200/AtNetworkNtpEC200.h"

#define GSM_NTP_CMD "AT+QLTS"
#define GSM_NTP_RES "+QLTS: \""

tm AtNetworkNtpEC200::getTimeStruct(uint32_t timeout) {
  struct tm result = {0, 0, 0, 0, 0, 0, 0, 0, 0};

  this->device->streamWriteClear(GSM_NTP_CMD GSM_NL);
  if (this->device->wait(GSM_NTP_RES) == AT_RCODE1) {
    result.tm_year = formatWithTmYear(this->device);
    result.tm_mon = formatWithTmMonth(this->device);
    result.tm_mday = formatWithTmDay(this->device);

    result.tm_hour = formatWithTmHour(this->device);
    result.tm_min = formatWithTmMin(this->device);
    result.tm_sec = formatWithTmSec(this->device);
  }

  return result;
}